package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.apkextract.lib.model.AeExportInfo;
import com.stark.apkextract.lib.model.AeExporter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.SearchApkAdapter;
import flc.ast.bean.ApkBean;
import flc.ast.databinding.ActivityRecentUninstallBinding;
import flc.ast.utils.AppSpUtils;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.utils.RxUtil;

public class RecentUninstallActivity extends BaseAc<ActivityRecentUninstallBinding> {

    private SearchApkAdapter uninstallAdapter;
    private List<ApkBean> listShow = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.activity_recent_uninstall;
    }

    @Override
    protected void initView() {
        mDataBinding.ivApkUninstallBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvUninstallList.setLayoutManager(new LinearLayoutManager(mContext));
        uninstallAdapter = new SearchApkAdapter();
        mDataBinding.rvUninstallList.setAdapter(uninstallAdapter);
        uninstallAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        ApkBean item = (ApkBean) adapter.getItem(position);
        ApkDetailsActivity.apkBean = item;
        startActivity(ApkDetailsActivity.class);
    }

    @Override
    protected void initData() {
        getData();
    }

    //获取卸载记录数据
    private void getData() {
        listShow.clear();
        List<ApkBean> listSp = AppSpUtils.getUninstallRecordList();
        if (listSp != null && listSp.size() > 0) {
            listShow.addAll(listSp);
            uninstallAdapter.setList(listShow);
            mDataBinding.rvUninstallList.setVisibility(View.VISIBLE);
            mDataBinding.tvApkUninstallNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvUninstallList.setVisibility(View.GONE);
            mDataBinding.tvApkUninstallNoData.setVisibility(View.VISIBLE);
        }
    }

}